<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/14
 * Time: 10:29
 */
$key=$_COOKIE['userkey'];
session_start();
if(!isset($_SESSION[$key])){
    echo '<a href="../login/loginUI.php">请重新登陆</a>';
    die;
}
//获取需要的基本数据
$card_no=$_SESSION[$key]['user_name'];
$card_money=$_SESSION[$key]['card_money'];
$money=$_POST['Transfer_money'];
$Transfer_card=$_POST['Transfer_card'];
//连接数据库
$conn=new  mysqli();
$conn->connect('127.0.0.1','root','root','bank');
//先查询这个账户是否存在；
$sql="SELECT * from bankcard where CardNo='$Transfer_card';";
$result=$conn->query($sql);
$data =$result->fetch_assoc();
if($data==null){
    echo '目标账户出错,请重新输入<br/><a href="Transfer.php"><button>返回</button></a>';
    die();
}
//本账户转出
if($card_money>=$money){
    $sql="UPDATE bankcard SET CardMoney=CardMoney-'$money' WHERE CardNo='$card_no';";
    $result=$conn->query($sql);
}else{
    echo '取款金额大于卡余额，取款失败,请重新输入<br/><a href="Transfer.php"><button>返回</button></a>';
    die();
}
//目标账户接收
$sql="UPDATE bankcard SET CardMoney=CardMoney+'$money' WHERE CardNo='$Transfer_card';";
$result=$conn->query($sql);
//跳转回用户界面
header('location:../loginAction.php');

